package cn.iocoder.boot.mapper;

import cn.iocoder.boot.dto.KbPlatformApiDTO;
import cn.iocoder.boot.entity.KbPlatformApi;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface KbPlatformApiMapper extends BaseMapper<KbPlatformApi> {

    /**
     * 分页查询
     */
    @Select({
            "<script>",
            "select system_users.username, kb_platform_api.* " +
                    "from kb_platform_api " +
                    "LEFT JOIN system_users ON kb_platform_api.user_id = system_users.id " +
                    "where kb_platform_api.deleted=0 " +
                    "<if test='platformApiDTO.userName != null'> " +
                    "AND system_users.username LIKE CONCAT('%', #{platformApiDTO.userName}, '%')" +
                    "</if>",
            "</script>"
    })
    Page<KbPlatformApiDTO> selectPageList(Page<KbPlatformApi> page, KbPlatformApiDTO platformApiDTO);

    @Select({
            "SELECT system_users.username, kb_platform_api.* ",
            "FROM kb_platform_api ",
            "LEFT JOIN system_users ON kb_platform_api.user_id = system_users.id ",
            "WHERE kb_platform_api.deleted = 0 ",
            "AND kb_platform_api.user_id = #{id}"
    })
    KbPlatformApi selectByUserId(Long id);

    @Select({
            "SELECT system_users.username, kb_platform_api.* ",
            "FROM kb_platform_api ",
            "LEFT JOIN system_users ON kb_platform_api.user_id = system_users.id ",
            "WHERE kb_platform_api.deleted = 0 ",
            "AND kb_platform_api.id = #{id}"
    })
    KbPlatformApi selectById(Long id);
}
